const { list, tags } = require("./mock");
module.exports = app => {
  app.get("/api/list", (req, res) => {
    const { _page = 1, _size = 10, wd = "" } = req.query;
    let newList = [...list];
    if (wd) {
      newList = newList.filter(v => {
        return JSON.stringify(v).includes(wd);
      });
    }
    if (_page * _size - _size <= newList.length) {
      res.send({
        code: 200,
        data: newList.slice((_page - 1) * _size, _page * _size),
      });
    } else {
      res.send({
        code: 400,
        data: null,
      });
    }
  });
  app.get("/api/tags", (_, res) => {
    res.send({
      code: 200,
      data: tags,
    });
  });
};
